﻿using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MiniErp.Common.Cache;
using MiniErp.Core.Filters;
using MiniErp.Entity.DataStreams.BOs;
using MiniErp.Entity.DataStreams.DOs;
using MiniErp.Entity.DataStreams.DTOs;
using MiniErp.Entity.DataStreams.DTOs.Users;
using MiniErp.Service.JWTService.IService;
using MiniErp.Service.BusinessService.IService;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

namespace MiniErp.Core.Controllers
{
    /// <summary>
    /// 登录注册控制层
    /// </summary>
    [Route("api/[controller]/[action]")]
    [TypeFilter(typeof(ExceptionFilter))]
    [TypeFilter(typeof(ResultFilter))]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IUserService _userService;
        private readonly ITokenService _tokensService;
        public UserController(IUserService userService, ITokenService tokensService)
        {
            _userService = userService;
            _tokensService = tokensService;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="uid">工号</param>
        ///  <param name="password">密码</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<string> Login(int uid, string password)
        {
            var users = await _userService.Login(uid, password);
            return _tokensService.GetToken(users);
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="registers">用户信息</param>
        /// <returns></returns>
        [HttpPost]
        public Task<bool> Register(RegisterDTO registers)
        {
            return _userService.Register(registers);
        }
        /// <summary>
        /// 查询打卡信息(定制api)
        /// </summary>
        /// <param name="uid">工号</param>
        /// <returns></returns>
        [HttpGet]
        public List<string> GetUserPunchInfo(int uid)
        {
            return _userService.GetUserPunchInfo(uid);
        }



    }
}
